<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">
        /**
        * @param {number[]} nums
        * @return {number}
        */
        var maxSubArray = function(nums) {
            var ans=nums[0];
            var sum=nums[0];
            for(var i=1;i<nums.length;i++)
            {
                ans=Math.max(ans+nums[i],nums[i]);
                sum=Math.max(sum,ans);
            }
            console.log(ans);
            return sum;
        };
        var a=[-2,1,-3,4,-1,2,1,-3,4];
        maxSubArray(a);
    </script>
</body>
</html>